using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace Promike.site.Models
{ 
    public class PhotoCategoryRepository : IPhotoCategoryRepository
    {
        PromikeContext context = new PromikeContext();

        public IQueryable<PhotoCategory> All
        {
            get { return context.PhotoCategories; }
        }

        public PhotoCategory Find(int id)
        {
            return context.PhotoCategories.Find(id);
        }

        public void InsertOrUpdate(PhotoCategory photocategory)
        {
            if (photocategory.Id == default(int)) {
                // New entity
                context.PhotoCategories.Add(photocategory);
            } else {
                // Existing entity
                context.Entry(photocategory).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var photocategory = context.PhotoCategories.Find(id);
            context.PhotoCategories.Remove(photocategory);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IPhotoCategoryRepository : IDisposable
    {
        IQueryable<PhotoCategory> All { get; }
        PhotoCategory Find(int id);
        void InsertOrUpdate(PhotoCategory photocategory);
        void Delete(int id);
        void Save();
    }
}